package o;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.text.TextUtils;
import java.util.List;

public abstract class ActivityUtil {
    private static boolean ˊ = false;
    private static boolean ˎ = false;

    public static boolean ˏ() {
        return ˎ;
    }

    public static void ॱ(boolean z) {
        ˎ = z;
    }

    public static boolean ˎ() {
        return ˊ;
    }

    public static void ˏ(boolean z) {
        ˊ = z;
    }

    public static boolean isAcitivtyNotValid(Context context) {
        if (context == null) {
            return true;
        }
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity.isFinishing() || activity.isDestroyed()) {
                Logger.ˋ("ActivityUtil", "activity has bean finished, cannot instance:" + activity);
                return true;
            }
        }
        return false;
    }

    public static void unregisterReceiver(Context context, BroadcastReceiver broadcastReceiver) {
        if (broadcastReceiver != null && context != null) {
            try {
                context.unregisterReceiver(broadcastReceiver);
            } catch (IllegalArgumentException e) {
                Logger.ˋ("ActivityUtil", "unregisterReceiver error:" + e.toString());
            }
        }
    }

    public static void registerReceiver(Context context, IntentFilter intentFilter, BroadcastReceiver broadcastReceiver) {
        if (intentFilter != null && broadcastReceiver != null && !isAcitivtyNotValid(context)) {
            try {
                context.registerReceiver(broadcastReceiver, intentFilter);
            } catch (IllegalArgumentException e) {
                Logger.ˋ("ActivityUtil", "registerReceiver error:" + e.toString());
            }
        }
    }

    public static boolean ॱ(Context context, String[] strArr) {
        if (context == null || epz.ॱ(strArr)) {
            return false;
        }
        List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
        if (!CollectCheck.isEmpty(runningTasks)) {
            String packageName = ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName();
            for (String equals : strArr) {
                if (equals.equals(packageName)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean ˏ(Context context) {
        if (context == null) {
            return false;
        }
        String packageName = context.getPackageName();
        List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
        if (!CollectCheck.isEmpty(runningTasks)) {
            Object packageName2 = ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName();
            if (!TextUtils.isEmpty(packageName2) && packageName2.equals(packageName)) {
                return true;
            }
        }
        return false;
    }

    public static boolean ˋ(Context context) {
        if (context == null) {
            return false;
        }
        List<RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) context.getSystemService("activity")).getRunningAppProcesses();
        if (runningAppProcesses == null) {
            return false;
        }
        for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
            if (runningAppProcessInfo.processName.equals(context.getPackageName()) && runningAppProcessInfo.importance == 100) {
                return true;
            }
        }
        return false;
    }

    public static boolean ˋ(Context context, String[] strArr) {
        if (context == null || epz.ॱ(strArr)) {
            return false;
        }
        List<RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) context.getSystemService("activity")).getRunningAppProcesses();
        if (runningAppProcesses == null) {
            return false;
        }
        String str = "";
        for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
            if (runningAppProcessInfo.importance == 100) {
                Object obj = runningAppProcessInfo.processName;
                break;
            }
        }
        String str2 = str;
        for (String equals : strArr) {
            if (equals.equals(obj)) {
                return true;
            }
        }
        return false;
    }

    public static boolean ॱ(Context context) {
        if (context == null) {
            return false;
        }
        String packageName = context.getPackageName();
        List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
        if (!CollectCheck.isEmpty(runningTasks)) {
            Object packageName2 = ((RunningTaskInfo) runningTasks.get(0)).baseActivity.getPackageName();
            if (!TextUtils.isEmpty(packageName2) && packageName2.equals(packageName)) {
                return true;
            }
        }
        return false;
    }
}
